<template>
  <div class="win">
    <!-- <frames title="积分兑换" bjimg="integral_bj.png" /> -->

    <!-- 头部 -->
    <div class="head_space"></div>
    <div class="head">
      <div class="container">
        <p v-if="userPhone==''||userPhone==undefined||userPhone==null" class="p2">0</p>
        <p v-else class="p2">{{integral}}</p>
        <p>您当前剩余积分</p>
      </div>
    </div>
    <!-- 商品 -->
    <div class="index_item_box">
      <div class="newRecommend_box">
        <div
          class="item"
          @click="hr_goodsDetail(item.intpro_id)"
          v-for="(item,t) in commodity"
          :key="t"
        >
          <img :src="item.image" />
          <div class="item_bottom_box">
            <P class="name ellipsis2">{{item.name}}</P>
            <div class="row_box">
              <div class="tips_box">
                <p
                  v-if="l<2"
                  :class="ite=='包邮'?'blue':'green'"
                  v-for="(ite, l) in item.label"
                  :key="l"
                >{{ite}}</p>
              </div>
            </div>
            <div class="money_box">
              <p class="money">{{item.convert_intergal}}积分</p>
              <p class="sales">销量：{{item.sale_num}}</p>
            </div>
          </div>
        </div>
      </div>
      <p class="bottom_list">到底了~</p>
    </div>
    <i-toast id="toast" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      bjurl: "",
      commodity: [], //商品列表
      integral: 0, //积分数量
      userPhone: "" //缓存用户手机号
    };
  },
  methods: {
    // 请求接口积分兑换商品
    getGoodsData() {
      this.$ajax("/home/integral/integral_index", "post", {})
        .then(res => {
          
          if (res.status) {
            this.integral = res.data.integral_count;
            this.commodity = res.data.detail;
          } else {
          }
        })
        .catch(err => {}); 
    },
    hr_goodsDetail(intpro_id) {
      wx.navigateTo({
        url: "../goodsDetail/main?intpro_id=" + intpro_id + "&type=" + 2
      });
    }
  },
  onShow() {
    this.userPhone = wx.getStorageSync("phone");
    this.getGoodsData();
  },
  onLoad(e) {
    Object.assign(this.$data, this.$options.data());
    this.bjurl = this.$bjurl;
  }
};
</script>

<style lang="scss" scoped>
.win {
  .head_space {
    height: 212rpx;
  }
  .head {
    width: 750rpx;
    height: 212rpx;
    background-image: url($bjurl+"integral_store_bj.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    .container {
      text-align: center;
      padding: 40rpx 0 30rpx 0;
      color: #f3f3f3;
      font-weight: 400;
      letter-spacing: 4rpx;
      font-size: 28rpx;
      font-weight: 400;
      .p2 {
        font-size: 60rpx;
        letter-spacing: 4rpx;
        margin-bottom: 34rpx;
      }
    }
  }
  .index_item_box {
    padding-bottom: 35rpx;
    .newRecommend_box {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      padding: 0 30rpx;
      .item {
        width: 333rpx;
        display: flex;
        flex-direction: column;
        margin-top: 20rpx;
        background-color: #ffffff;
        border-radius: 20rpx;
        box-shadow: 0rpx 4rpx 40rpx 0rpx rgba(0, 0, 0, 0.11);
        img {
          width: 333rpx;
          height: 331rpx; //固定高度后期修改
          border-radius: 20rpx 20rpx 0 0;
        }
        .item_bottom_box {
          height: 160rpx;
          box-sizing: border-box;
          padding: 10rpx 12rpx 15rpx 20rpx;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .name {
            width: 300rpx;
            color: #4d4d4d;
            font-size: 26rpx;
            line-height: 1.1;
            font-weight: bold;
          }
          .row_box {
            display: flex;
            align-items: flex-end;
            .tips_box {
              display: flex;
              align-items: flex-end;
              font-size: 18rpx;
              p {
                color: #6da9ff;
                padding: 5rpx 14rpx 7rpx;
                background-color: #deebff;
                border-radius: 15rpx;
                margin-right: 10rpx;
              }
              :first-child {
                color: #ffffff;
                background-color: $green;
              }
            }
            .cost_money {
              font-size: 26rpx;
              color: #b3b3b3;
              text-decoration: line-through;
            }
          }
          .money_box {
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
            .money {
              color: $red;
              line-height: 0.9;
              font-size: 30rpx;
            }
            .sales {
              font-size: 20rpx;
              color: #7c7c7c;
            }
          }
        }
      }
    }
    .bottom_list {
      margin-top: 40rpx;
      text-align: center;
      font-size: 30rpx;
      color: #999999;
    }
  }
}
</style>
